package service.impl;

import dao.BookDao;
import dao.impl.BookDaoImpl;
import domain.Book;
import domain.Chapter;
import domain.Word;
import service.BookService;

import java.util.List;

public class BookServiceImpl implements BookService {
    @Override
    public void creatBook(Book book){
        //void addBook(String cover, String name, String brief, int uid);
        BookDao bd = new BookDaoImpl();
        bd.addBook(book.getCover(),book.getName(),book.getBrief(),book.getUid());
    }

    @Override
    public void modifyBook(Book book){
        BookDao bd = new BookDaoImpl();
        bd.modifyBook(book.getBid(),book.getCover(),book.getName(),book.getBrief());
    }

    @Override
    public void addChapter(Chapter chapter){
        BookDao bd = new BookDaoImpl();
        bd.addCapter(chapter.getBid(),chapter.getName(),chapter.getContent());
    }

    @Override
    public void addWordList(List<Word> wordList) {
        BookDao bd = new BookDaoImpl();
        for(Word word:wordList){
            bd.addBookWord(word.getWord(),word.getFrequency(),word.getBid());
        }
    }

    @Override
    public List<Book> getCommonBook() {
        BookDao bd = new BookDaoImpl();
        return bd.getCommonBook();
    }

    @Override
    public List<Chapter> getCapterNameList(Book book) {
        return new BookDaoImpl().getCapterNameList(book.getBid());
    }

    @Override
    public Chapter getChapter(Chapter chapter) {
        return new BookDaoImpl().getCapter(chapter.getCid());
    }

    @Override
    public Book getBookbybid(int bid) {
        return new BookDaoImpl().getBookbybid(bid);
    }

    @Override
    public void addBookWord(List<Word> wordList) {
        new BookDaoImpl().addBookWord(wordList);
    }

    @Override
    public void delBookWord(int bid) {
        new BookDaoImpl().delBookWord(bid);
    }
}
